Tutorial step 1: creating the main routines |
The main routine of any VirtualDub filter is the run function, which has this prototype:
int runProc(const FilterActivation *fa, const FilterFunctions *ff);
The main items of interest are in the fa parameter:
Both structures are of type VBitmap. The main fields are:
Creating a dummy function |
Here is a skeletal runProc function that simply runs source and destination pointers over the bitmap:
int tutorialRunProc(const FilterActivation *fa, const FilterFunctions *ff) {
PixDim w, h;
Pixel32 *src, *dst;
src = (Pixel32 *)fa->src.data;
dst = (Pixel32 *)fa->dst.data;
h = fa->src.h;
do {
w = fa->src.w;
do {
++src, ++dst;
} while(--w);
src = (Pixel32 *)((char *)src + fa->src.modulo);
dst = (Pixel32 *)((char *)dst + fa->dst.modulo);
} while(--h);
return 0;
}
Note that because VirtualDub bitmaps are inverted like Windows DIBs, this routine scans from bottom to top. Scanlines are still left-to-right, though.
Implementing our color shift |
We want to emphasize green, and deemphasize blue. The easiest way to do this is to halve both blue and green, and to add 50% to green. 32-bit RGB format defines 8-bits for each pixel in 0xRRGGBB format, so we'll use this as our pixel alteration formula:
new_pixel = (old_pixel & 0xFF0000) + ((old_pixel & 0x00FEFE)>>1) + 0x008000;
This breaks down as follows:
Now we can write this into our inner loop:
int tutorialRunProc(const FilterActivation *fa, const FilterFunctions *ff) {
PixDim w, h;
Pixel32 *src, *dst;
src = (Pixel32 *)fa->src.data;
dst = (Pixel32 *)fa->dst.data;
h = fa->src.h;
do {
w = fa->src.w;
do {
Pixel32 old_pixel, new_pixel;
old_pixel = *src++;
new_pixel = (old_pixel & 0xFF0000) + ((old_pixel & 0x00FEFE)>>1) + 0x008000;
*dst++ = new_pixel;
} while(--w);
src = (Pixel32 *)((char *)src + fa->src.modulo);
dst = (Pixel32 *)((char *)dst + fa->dst.modulo);
} while(--h);
return 0;
}
That's it! We're done with the main processing routine, for now.
back to main page
tutorial[0]: designing the filter
tutorial[2]: creating the FilterDefinition structure
VirtualDub external filter SDK 1.05 | ©1999-2001 Avery Lee <phaeron@virtualdub.org> |